home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / xprzmodem.h < prev    next >
C/C++ Source or Header  |  1995-04-22  |  10KB  |  218 lines

  1. /*
  2.  *  xprzmodem.h: Definitions for xprzmodem.library;
  3.  *  Version 3.0, 05 Apr 1995, by A. Preston for Citadel
  4.  *  Version 2.0, 28 October 1989, by Rick Huebner.
  5.  *  Released to the Public Domain; do as you like with this code.
  6.  */
  7.  
  8. /* #define DEBUGLOG 1 */
  9.  
  10. /* Return codes */
  11. #define OK        0
  12. #define ZM_ERROR   (-1)
  13. #define TIMEOUT (-2)
  14. #define RCDO    (-3)
  15.  
  16. /* Relevant control characters */
  17. #define CR      ('M' & 0x1F)    /* ^M */
  18. #define ZM_XON     ('Q' & 0x1F)    /* ^Q */
  19. #define ZM_XOFF    ('S' & 0x1F)    /* ^S */
  20. #define ZM_CAN     ('X' & 0x1F)    /* ^X */
  21. #define ZM_CPMEOF  ('Z' & 0x1F)    /* ^Z */
  22.  
  23. /* Misc. program constants */
  24. #define LZMANAG           0     /* Default ZMODEM file management mode */
  25. #define LZTRANS           0     /* Default ZMODEM file transport mode */
  26. #define PATHLEN         256     /* What's the max legal path size? */
  27. #define CONFIGLEN        32     /* Max length of transfer options string */
  28. #define KSIZE          1024     /* Max allowable packet size */
  29. #define MINBLOCK         64     /* Min allowable packet size */
  30. #define MAXGOODNEEDED  8192     /* Max # good bytes req'd to bump packet size */
  31.  
  32. /* Provision for future 7-bit ZMODEM; for now, there's no difference */
  33. #define sendline xsendline
  34.  
  35. /*
  36.  * Replacement for global variables normally used, in order to make code
  37.  * fully reentrant; each invocation allocs their own Vars, and passes the
  38.  * struct pointer down through the entire program so they're always available.
  39.  * Pointer to this struct is usually able to be a register variable, so access
  40.  * is no worse than any stack variable (all register-relative).  Kinda
  41.  * kludgey, but the original ZModem code design depended on lots of globals,
  42.  * and I didn't want to redesign the whole damn thing.  Besides, it's more
  43.  * efficient than constantly pushing & popping args all over the place.
  44.  */
  45.  
  46. struct Vars
  47. {
  48.   struct XPR_IO io;             /* Copy of XProto IO struct passed by term prog. */
  49.   struct XPR_UPDATE __aligned xpru;       /* Scratchpad xpr_update() control struct */
  50.   struct timeval    __aligned Starttime;  /* Time transfer started */
  51.   UBYTE             __aligned Rxhdr[4];   /* Received header */
  52.   UBYTE Txhdr[4];               /* Transmitted header */
  53.   UBYTE Msgbuf[128];            /* Scratchpad buffer for printing messages */
  54.   UBYTE Filename[PATHLEN];      /* Name of the file being up/downloaded */
  55.   UBYTE Pktbuf[KSIZE];          /* File data packet buffer */
  56.   UBYTE Modembuf[KSIZE * 4 + 256];      /* Input buffer for data from modem */
  57.   UBYTE Outbuf[KSIZE * 4 + 256];        /* Output buffer for data to modem */
  58.   UBYTE *Modemchar;             /* Next char to get from Modembuf */
  59.   UBYTE *Filebuf;               /* File I/O buffer address */
  60.   UBYTE *Filebufptr;            /* Current position within Filebuf */
  61.   ULONG Modtime;                /* Modification data. */
  62.   ULONG Bits;                   /* Attribute bits. */
  63.   ULONG BytesSent;              /* How many bytes sent since last check. */
  64.   ULONG BytesReceived;          /* How many bytes received since last check. */
  65.   LONG Receiving;               /* Receiving or sending? */
  66.   FILE  *File;                  /* Handle of file being transferred */
  67.   long Oldstatus;               /* Original terminal program's modem settings */
  68.   long Baud;                    /* BPS setting of modem */
  69.   long Strtpos;                 /* Starting byte position of transfer */
  70.   long Fsize;                   /* Size of file being transferred */
  71.   long Rxbytes;                 /* Number of bytes received so far */
  72.   long Filebufpos;              /* File offset of data in Filebuf */
  73.   long Filebufmax;              /* Size of Filebuf */
  74.   long Filebuflen;              /* Number of bytes currently stored in Filebuf */
  75.   long Filebufcnt;              /* Number of bytes remaining/written in Filebuf */
  76.   long Rxpos;                   /* Received file position */
  77.   long Txpos;                   /* Transmitted file position */
  78.   short Filcnt;                 /* Number of files opened for transmission */
  79.   short Errcnt;                 /* Number of files unreadable */
  80.   short Noroom;                 /* Flags 'insufficient disk space' errors */
  81.   short Rxbuflen;               /* Largest frame they're willing to xfer */
  82.   short Tframlen;               /* Largest frame we're willing to xfer */
  83.   short Rxtimeout;              /* Tenths of seconds to wait for something */
  84.   short Tryzhdrtype;            /* Header type to send corresp to Last rx close */
  85.   short Modemcount;             /* Number of bytes available in Modembuf */
  86.   short Outbuflen;              /* Number of bytes currently stored in Outbuf */
  87.   short Rxframeind;             /* ZBIN or ZHEX; type of frame received */
  88.   short Txfcs32;                /* TRUE means send binary frame with 32 bit FCS */
  89.   short Rxflags;                /* Temp register */
  90.   short Wantfcs32;              /* want to send 32 bit FCS */
  91.   short Crc32t;                 /* Display flag indicates 32 bit CRC being sent */
  92.   short Crc32;                  /* Display flag indicates 32 bit CRC being recd */
  93.   short Rxtype;                 /* Type of header received */
  94.   short Rxcount;                /* Count of data bytes received */
  95.   short Znulls;                 /* Number of nulls to send at begin of ZDATA hdr */
  96.   short ErrorLimit;             /* How many sequential errors before abort */
  97.   short Zctlesc;                /* Are ctl chars to be escaped? */
  98.   short FileAttributes;         /* Bit 0: send file attributes, bit 1: honor file attributes received. */
  99.   char SetAttributes;           /* Set file attributes and time? */
  100.   char Rxbinary;                /* Force binary mode download? */
  101.   char Rxascii;                 /* Force text mode download? */
  102.   char Thisbinary;              /* Receive this file in binary mode? */
  103.   char Lzconv;                  /* Suggested binary/text mode for uploads */
  104.   char Eofseen;                 /* Text-mode EOF marker (^Z) rec'd on download? */
  105.   UBYTE Zconv;                  /* ZMODEM file conversion request */
  106.   UBYTE Zmanag;                 /* ZMODEM file management request */
  107.   UBYTE Ztrans;                 /* ZMODEM file transport request */
  108.   UBYTE Lastsent;               /* Last text char written by putsec() */
  109.   UBYTE Lastzsent;              /* Last char sent by zsendline() */
  110.   UBYTE Fileflush;              /* Flush file I/O buffer before closing? */
  111.   UBYTE Attn[ZATTNLEN + 1];     /* Attention string rx sends to tx on err */
  112.   LONG ksize;                   /* Max allowable packet size */
  113. };
  114.  
  115. /*
  116.  * Option settings and other variables needed outside of XProtocolSend/Receive;
  117.  * separated from rest of Vars so that huge Vars struct doesn't have to be
  118.  * allocated except during transfers.  Pointer to this struct kept in xpr_data.
  119.  */
  120. struct SetupVars
  121. {
  122.   UBYTE *matchptr, *bufpos;
  123.   short buflen;
  124.   UBYTE option_t[2], option_o[2], option_b[8], option_f[8], option_e[8],
  125.     option_s[4];
  126.   UBYTE option_c[4], option_r[4], option_a[4], option_d[4], option_k[4],
  127.     option_p[256], option_m[8];
  128.   UBYTE option_i[2];
  129. };
  130.  
  131. /* Function prototypes */
  132.  
  133. long XProtocolSend( struct XPR_IO *xio);
  134. short getzrxinit(struct Vars *v);
  135. short sendzsinit(struct Vars *v);
  136. void sendbatch(struct Vars *v);
  137. short sendone(struct Vars *v);
  138. short sendname(struct Vars *v);
  139. short zsendfile(struct Vars *v, short blen);
  140. short zsendfdata(struct Vars *v);
  141. short getinsync(struct Vars *v);
  142. void saybibi(struct Vars *v);
  143.  
  144. long  XProtocolReceive( struct XPR_IO *xio);
  145. short rcvbatch(struct Vars *v);
  146. short tryz(struct Vars *v);
  147. short rzfiles(struct Vars *v);
  148. short rzfile(struct Vars *v);
  149. short procheader(struct Vars *v);
  150. short putsec(struct Vars *v);
  151. void ackbibi(struct Vars *v);
  152.  
  153. long XProtocolSetup(struct XPR_IO *xio);
  154. long XProtocolCleanup(struct XPR_IO *xio);
  155. long XProtocolHostMon(struct XPR_IO *xio, char *serbuff, long actual, long maxsize);
  156. long XProtocolUserMon(struct XPR_IO *xio, char *serbuff, long actual, long maxsize);
  157. struct Vars *setup(struct XPR_IO *io);
  158. UBYTE *find_option(UBYTE * buf, UBYTE option);
  159. void set_textmode(struct Vars *v);
  160. void canit(struct Vars *v);
  161. void zmputs(struct Vars *v, UBYTE * s);
  162. void xsendline(struct Vars *v, UBYTE c);
  163. void sendbuf(struct Vars *v);
  164. short readock(struct Vars *v, short tenths);
  165. char char_avail(struct Vars *v);
  166. void update_rate(struct Vars *v);
  167. FILE * bfopen(struct Vars *v, UBYTE * mode);
  168. void bfclose(struct Vars *v);
  169. void bfseek(struct Vars *v, long pos);
  170. long bfread(struct Vars *v, UBYTE * buf, long length);
  171. long bfwrite(struct Vars *v, UBYTE * buf, long length);
  172. void ioerr(struct XPR_IO *io, char *msg);
  173. void upderr(struct Vars *v, char *msg);
  174. void updmsg(struct Vars *v, char *msg);
  175. long getfree(struct Vars *v);
  176. char exist(struct Vars *v);
  177.  
  178. void mysprintf(STRPTR, STRPTR,...);
  179. LONG Atol(STRPTR buffer);
  180. void kprintf(STRPTR,...);
  181.  
  182. extern struct ExecBase *SysBase;
  183. extern struct DosLibrary *DOSBase;
  184. extern struct Library *UtilityBase;
  185. extern struct Library *TimerBase;
  186. extern LONG GMT_Offset;
  187.  
  188. void zsbhdr(struct Vars *v, USHORT type);
  189. void zshhdr(struct Vars *v, USHORT type);
  190. void zsdata(struct Vars *v, short length, USHORT frameend);
  191. short zrdata(struct Vars *v, UBYTE * buf, short length);
  192. short zrdat32(struct Vars *v, UBYTE * buf, short length);
  193. short zrdatr32(struct Vars *v, UBYTE * buf, short length);
  194. short zgethdr(struct Vars *v);
  195. short zrbhdr(struct Vars *v);
  196. short zrbhdr32(struct Vars *v);
  197. short zrhhdr(struct Vars *v);
  198. void zputhex(struct Vars *v, UBYTE c);
  199. void zsendline(struct Vars *v, UBYTE c);
  200. short zgethex(struct Vars *v);
  201. short zdlread(struct Vars *v);
  202. short noxrd7(struct Vars *v);
  203. void stohdr(struct Vars *v, long pos);
  204. long rclhdr(struct Vars *v);
  205. void xpr_fwrite(char *, long, long, FILE *);
  206.  
  207. /*
  208.  * # seconds between 1-1-70 (Unix time base) and 1-1-78 (Amiga time base).
  209.  * Add this value to the returned seconds count to convert Amiga system time
  210.  * to normal Unix system time.
  211.  */
  212.  
  213. #define UTC_OFFSET 252482400
  214.  
  215. ULONG getsystime(struct timeval *tv);
  216.  
  217. /* End of XprZmodem.h source */
  218.